import pymysql
import time

while True:
    host = "gz-cdb-5gusw5gx.sql.tencentcdb.com"
    username = "wangzhijing"
    password = "wangzhijing"
    dbname = "hardware_open"
    port = 63044
    db = pymysql.connect(host, username, password, dbname, port)
    cursor1 = db.cursor()
    cursor2 = db.cursor()
    x = str(input("请输入要查询的SN或台卡链接："))
    if 13 < len(x) < 24:
        sql1 = "SELECT sn, card_qrcode FROM card_qrcode WHERE sn='" + x + "'"
        sql2 = "SELECT appid,password,token FROM hardware_list where sn='" + x + "'"
        cursor1.execute(sql1)
        cursor2.execute(sql2)
        result1 = cursor1.fetchall()
        result2 = cursor2.fetchall()
        print(str(result2).strip("((),)"), ",", str(result1).strip("((),)"))
        db.close()
        time.sleep(20)
        break
    elif 28 < len(x) < 30:
        sql = "SELECT card_qrcode,sn FROM card_qrcode WHERE card_qrcode='" + x + "'"
        cursor1.execute(sql)
        result1 = cursor1.fetchall()
        print(str(result1).strip("((),)"))
        db.close()
        time.sleep(20)
        break
    else:
        print("输入错误，重新输入！")
        continue
